package org.example.dingtalkintegrationservice.repository;
import org.example.dingtalkintegrationservice.pojo.IdRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.Optional;
/**
 * @author pc
 */
@Repository
public interface IdRecordRepository extends JpaRepository<IdRecord, Integer>, JpaSpecificationExecutor<IdRecord> {
    Optional<IdRecord> findById1(String id1);
    @Query(value = "SELECT  * FROM id_record r WHERE r.id1 = ?1 ORDER BY r.create_time DESC LIMIT 1 ;",nativeQuery = true)
    Optional<IdRecord> findLatestById1(String id1);
    @Query(value = "SELECT  * FROM id_record r WHERE r.id1 = ?1 and r.user_id=?2 ORDER BY r.create_time DESC LIMIT 1 ;",nativeQuery = true)
    Optional<IdRecord> findLatestById1AndUserId(String id1,String userId);
}